package com.demo.controller;

import com.demo.entity.VtePreventive;
import com.demo.response.Result;
import com.demo.service.IVtePreventiveService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * vte诊断评估表 前端控制器
 *
 * @author zm
 * @since 2020-12
 */
@RestController
@RequestMapping("/vtePreventive")
@Api(tags = "VTE评估")
public class VtePreventiveController {
    @Autowired
    IVtePreventiveService iVtePreventiveService;

    @ApiOperation("新增vte诊断评估")
    @PostMapping("/addVtePreventive")
    public Result addVtePreventive(@Validated @RequestBody VtePreventive vtePreventive, BindingResult result) throws Exception {
        if (result.hasErrors()) {
            return Result.error(result.getFieldError().getDefaultMessage());
        }
        return Result.success(iVtePreventiveService.addVtePreventive(vtePreventive));
    }

    @ApiOperation("更新vte诊断评估")
    @PostMapping("/updateVtePreventive")
    public Result updateVtePreventive(@RequestBody VtePreventive vtePreventive, BindingResult result) throws Exception {
        if (result.hasErrors()) {
            return Result.error(result.getFieldError().getDefaultMessage());
        }
        return iVtePreventiveService.updateVtePreventive(vtePreventive);
    }

    @ApiOperation("删除vte诊断评估")
    @GetMapping("/deleteVtePreventive")
    public Result deleteVtePreventive(@RequestParam(name = "vtePreventiveId", required = true) Integer vtePreventiveId,
                                      @RequestParam(name = "deletedUserId", required = true) Integer deletedUserId) {
        return iVtePreventiveService.deleteVtePreventive(vtePreventiveId, deletedUserId);
    }

    @ApiOperation(value = "vte诊断评估列表", tags = {"VTE评估", "v20210419更新"})
    @GetMapping("vtePreventiveList")
    public Result vtePreventiveList(@RequestParam(name = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                                    @RequestParam(name = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                    @RequestParam(name = "vtePreventiveId", required = false) Integer vtePreventiveId,
                                    @RequestParam(name = "patientId", required = false) Integer patientId) {
        return iVtePreventiveService.vtePreventiveList(pageNumber, pageSize, vtePreventiveId, patientId);
    }


    @ApiOperation(value = "VTE--护士签字")
    @GetMapping("/nurseSignature")
    public Result nurseSignature(@RequestParam(name = "preventiveType") Integer preventiveType,
                                 @RequestParam(name = "patientId") Integer patientId,
                                 @RequestParam(name = "vtePreventiveId") Integer vtePreventiveId,
                                 @RequestParam(name = "riskConfirmUserId") Integer riskConfirmUserId,
                                 @RequestParam(name = "preventiveRiskRank", required = false) Integer preventiveRiskRank,
                                 @RequestParam(name = "preventiveRiskScore") Integer preventiveRiskScore,
                                 @RequestParam(name = "userPass") String userPass) throws Exception {
        iVtePreventiveService.nurseSignature(preventiveType, patientId, vtePreventiveId, riskConfirmUserId, preventiveRiskRank, preventiveRiskScore, userPass);
        return Result.success();
    }

    @ApiOperation(value = "VTE--医生签字")
    @GetMapping("/doctorsSignature")
    public Result doctorsSignature(@RequestParam(name = "patientId", required = false) Integer patientId,
                                   @RequestParam(name = "vtePreventiveId") Integer vtePreventiveId,
                                   @RequestParam(name = "signUserId") Integer signUserId,
                                   @RequestParam(name = "userPass") String userPass) throws Exception {
        iVtePreventiveService.doctorsSignature(patientId, vtePreventiveId, signUserId, userPass);
        return Result.success();
    }


}
